package com.bruce.tool.map.core.handler;

/**
 * 距离计算
 * @author Bruce(刘正航)
 */
public class DistanceHandler {

    /**
     * 地球半径
     */
    public static double EARTH_RADIUS = 6371229;

    /**
     * 计算坐标之间的直线距离
     */
    public static double getDistance(double lat1, double longt1, double lat2,
                                     double longt2) {
        double x, y, distance;
        x = (longt2 - longt1) * Math.PI * EARTH_RADIUS
                * Math.cos(((lat1 + lat2) / 2) * Math.PI / 180) / 180;
        y = (lat2 - lat1) * Math.PI * EARTH_RADIUS / 180;
        distance = Math.hypot(x, y);
        return distance;
    }
}
